package com.ruoyi.devices.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.xag.domain.iotdevice.IotDevice;
import com.ruoyi.xag.service.DeviceService;
import com.ruoyi.ys7Video.domain.DeviceInfo;
import com.ruoyi.ys7Video.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * @author LiSuxuan
 * @date 2021年 07月 13日 15:16
 * <p>
 * 设备管理控制类
 */
@Api("设备管理控制类")
@Slf4j
@RestController
@RequestMapping("/devices")
public class DevicesController extends BaseController {

    @Autowired
    private DeviceService iotDeviceService;

    @Autowired
    private VideoService ys7VideoService;

    /**
     * 查询iot设备列表
     *
     * @return list 数据
     */
    @ApiOperation("查询iot设备列表")
    @GetMapping("/iotList")
    public AjaxResult iotDevicesList() {
        List<IotDevice> iotDevices = null;
        try {
            iotDevices = iotDeviceService.selectDeviceList();
        } catch (IOException e) {
            e.printStackTrace();
            return AjaxResult.error("查询列表出错，请检查!");
        }
        return AjaxResult.success(iotDevices);
    }

    /**
     * 根据设备id查询iot设备信息
     *
     * @return list 数据
     */
    @ApiOperation(value ="根据设备id查询iot设备信息",notes = "示例:http://192.168.1.217:8180//devices/selectDeviceInfoByDeviceId\n请求头附带设备id")
    @PostMapping("/selectDeviceInfoByDeviceId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId",value="设备id",paramType = "query",dataType = "String"),
    })
    public AjaxResult iotDevicesList(@RequestParam("deviceId") String deviceId) {
        IotDevice deviceInfo=null;
        try {
            deviceInfo = iotDeviceService.selectDeviceInfo(deviceId);

        } catch (IOException e) {
            e.printStackTrace();
            return AjaxResult.error("查询设备信息出错，请检查!");
        }
        return AjaxResult.success(deviceInfo);
    }

    /**
     * 查询 萤石云 设备列表
     *
     * @return list 数据
     */
    @ApiOperation("查询 萤石云 设备列表")
    @GetMapping("/ys7List")
    public AjaxResult ys7DevicesList() {
        List<DeviceInfo> result = ys7VideoService.ys7DeviceList();
        return AjaxResult.success(result);
    }





}
